if not ( RES_DISTRIB == 2 ) then Error("Please Install Resource Distribution 2 Addon.'" ) return end

TOOL.Category = '(Food Mod)'
TOOL.Name = '#Beer Tanks'
TOOL.Command = nil
TOOL.ConfigName = ''
if (CLIENT and GetConVarNumber("RD_UseLSTab") == 1) then TOOL.Tab = "Life Support" end

TOOL.ClientConVar['type'] = 'beer_tank'
TOOL.ClientConVar['model'] = 'models/props_junk/PropaneCanister001a.mdl'

cleanup.Register('beertanks')

if ( CLIENT ) then
	language.Add( 'Tool_beertanks_name', 'Beer Tanks' )
	language.Add( 'Tool_beertanks_desc', 'Create Tank attached to any surface.' )
	language.Add( 'Tool_beertanks_0', 'Left-Click: Spawn a Device.  Right-Click: Repair Device.' )

	language.Add( 'Undone_beertanks', 'Tank Undone' )
	language.Add( 'Cleanup_beertanks', 'Beer Tanks' )
	language.Add( 'Cleaned_beertanks', 'Cleaned up all Beer Tanks' )
	language.Add( 'SBoxLimit_foodmod', 'Maximum Food Generators Reached. Too Bad.' )
end

local beertanks = {}
if (SERVER) then
	beertanks.beer_tank = function( ply, ent, system_type, system_class, model )
		local rtable, maxhealth, mass = {}, 0, 0
		if (model == "models/props_junk/PropaneCanister001a.mdl") then
			maxhealth = 300
			mass = 20
			RD_AddResource(ent, "beer", 1000)
		elseif (model == "models/props_borealis/bluebarrel001.mdl") then
			maxhealth = 600
			mass = 200
			RD_AddResource(ent, "beer", 6000)
		elseif (model == "models/props/de_nuke/fuel_cask.mdl") then
			maxhealth = 2000
			mass = 2000
			RD_AddResource(ent, "beer", 24000)
		end
		rtable.mass = mass
		LS_RegisterEnt(ent, "Storage")
		return rtable, maxhealth, mass
	end
	
	beertanks.barley_tank = function( ply, ent, system_type, system_class, model )
		local rtable, maxhealth, mass = {}, 0, 0
		if (model == "models/props_borealis/bluebarrel001.mdl") then
			maxhealth = 600
			mass = 200
			RD_AddResource(ent, "barley", 6000)
		end
		rtable.mass = mass
		LS_RegisterEnt(ent, "Storage")
		return rtable, maxhealth, mass
	end

	beertanks.malt_tank = function( ply, ent, system_type, system_class, model )
		local rtable, maxhealth, mass = {}, 0, 0
		if (model == "models/props_borealis/bluebarrel001.mdl") then
			maxhealth = 600
			mass = 200
			RD_AddResource(ent, "malt", 6000)
		end
		rtable.mass = mass
		LS_RegisterEnt(ent, "Storage")
		return rtable, maxhealth, mass
	end

	beertanks.hops_tank = function( ply, ent, system_type, system_class, model )
		local rtable, maxhealth, mass = {}, 0, 0
		if (model == "models/props_borealis/bluebarrel001.mdl") then
			maxhealth = 600
			mass = 200
			RD_AddResource(ent, "hops", 6000)
		end
		rtable.mass = mass
		LS_RegisterEnt(ent, "Storage")
		return rtable, maxhealth, mass
	end

	beertanks.yeast_tank = function( ply, ent, system_type, system_class, model )
		local rtable, maxhealth, mass = {}, 0, 0
		if (model == "models/props_borealis/bluebarrel001.mdl") then
			maxhealth = 600
			mass = 200
			RD_AddResource(ent, "yeast", 6000)
		end
		rtable.mass = mass
		LS_RegisterEnt(ent, "Storage")
		return rtable, maxhealth, mass
	end
end

local beertanks_models = {
	{ 'Small Beer Tank', 'models/props_junk/PropaneCanister001a.mdl', 'beer_tank' },
	{ 'Large Beer Tank', 'models/props_borealis/bluebarrel001.mdl', 'beer_tank' },
	{ 'Barley Tank', 'models/props_borealis/bluebarrel001.mdl', 'barley_tank' },
	{ 'Malt Tank', 'models/props_borealis/bluebarrel001.mdl', 'malt_tank' },
	{ 'Yeast Tank', 'models/props_borealis/bluebarrel001.mdl', 'yeast_tank' },
	{ 'Huge Beer Tank', 'models/props/de_nuke/fuel_cask.mdl', 'beer_tank' },
	{ 'Hops Tank', 'models/props_borealis/bluebarrel001.mdl', 'hops_tank' },
}

RD2_ToolRegister( TOOL, beertanks_models, nil, "beertanks", 30, beertanks )
